#ifndef soundSpot_h
#define soundSpot_h

#include "LivingSpot.h"
#include "classMidi.h" // no need for declaring object members, but we need the global object myMidi defined as external in the midi class

class soundSpot: public LivingSpot {
 protected: 
   
 public: 
   soundSpot(); 
 
  // HARDWARE SENDING MODE (can be changed by serial or osc commands):
  boolean sendSerialMode;
  boolean sendOSCMode;
  boolean sendMIDIMode;

  // SENDING MODE (can be changed by serial or osc commands):
  boolean sendingPosition;
  boolean sendingColor; // in fact, mean intensity of the saccade
  boolean sendingCollision;
  boolean sendingTouchWall;
  boolean sendAngle; 
 
  void sendData(void); // this will swnd the data on Serial and/or OSC and/or MIDI
};

soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..}
 
  // DEFAULT HARDWARE SENDING MDOE: 
 sendSerialMode=false;
 sendOSCMode=false;
 sendMIDIMode=false;

  // DEFAULT SENDING MODE:
 sendingPosition=false;
 sendingColor=false; // in fact, mean intensity of the saccade
 sendingCollision=false;
 sendingTouchWall=false;
 sendAngle=false; 
 
 // for tests: NOTE: this won't work, because the constructor is called before the setup function that enables the following functions to work!!!!!!!
  //pinMode(31, OUTPUT); digitalWrite(31,HIGH); delay(200); digitalWrite(31, LOW); delay(200); digitalWrite(31,HIGH); delay(200); digitalWrite(31, LOW);   delay(200); digitalWrite(31,HIGH); 
 
}

void soundSpot::sendData() {
  
  // Position: 
 if (sendingPosition) {

  if (sendSerialMode) {    
     Serial.print(int(getX()), DEC);  // rem: getX gives a float between 0 and 4000
     Serial.print('X'); 
     Serial.print(int(getY()), DEC);
     Serial.print('Y'); 
     Serial.print(identifier);
     Serial.print('I'); // for identifier (this will enable setting the coordinates for the proper spot
     // on the processing program).  
  }
  if (sendOSCMode) {
       long    x, y;    //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
     //double  v2 = 0.0;  //double only ( not float) 
     x=(long)getX(); y=(long)getY();
   
     // set address and subaddress of sending message: 
    sendMes.setTopAddress(spotName); 
    sendMes.setSubAddress("/pos"); 
      // send positions as integers for THIS spot (perhaps it would be better to send all the data at once for all the spots?):
    sendMes.setArgs( "ii", &x, &y);
     osc.sendOsc( &sendMes );
  }
  if (sendMIDIMode) {
      
  }
 }
 
 // Color: 
  if (sendingColor) {
    if (sendSerialMode) {
    
    }
    if (sendOSCMode) {
    
    }
    if (sendMIDIMode) {
    
    }
  }
  
   
   // Collision: 
  if (sendingCollision&&collision) {
    if (sendSerialMode) {
    
    }
    if (sendOSCMode) {
    
    }
    if (sendMIDIMode) {
        // byte radius = -20*sin(200 * (millis()-schedulerTime) / 50000.0)+80 ;
         //midiNoteOn(0, radius, 127);
        myMidi.midiCollision(identifier, target_angle);
        //midiCollisionPercussion(i);
        // midiTouchWall(i);  
    
    }
  }
    
    // Walls: 
     if (sendingTouchWall&touchWall) {
    if (sendSerialMode) {
    
    }
    if (sendOSCMode) {
    
    }
    if (sendMIDIMode) {
      myMidi.midiTouchWall(identifier); //midiCollisionPercussion(i);
    }
 }
 
 // Angle: 
     if (sendAngle) {
    if (sendSerialMode) {
    
    }
    if (sendOSCMode) {
    
    }
    if (sendMIDIMode) {
    
    }
 }
 
  
  }

#endif

